<?php
class bannedList extends MY_Controller
{
	public function __construct()
	{
		log_message('debug', '=====开始调用Role->bannedList->__construct接口=====');
		parent::__construct();
		$this->loadLanguageFile('application/controllers/Role/');
		log_message('debug', '=====调用Role->bannedList->__construct接口结束=====');
	}
	
	public function showView() {
		$this->load->view('module/Role/bannedList.htm');
	}
	
	public function getListData() {
		log_message('debug', '=====开始调用Role->bannedList->getListData接口=====');
		$this->verifyPrivilege();
		
		try{
			$gameAreaId = $this->param->getParam('gameAreaId', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 201, 'invalidErrorCode' => 1));
			$bannedTypeId = $this->param->getParam('bannedTypeId', array('method' => 'int', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post');
			$page = $this->param->getParam('page', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$rows = $this->param->getParam('rows', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);

			$this->initGameAreaInfo($gameAreaId);

			switch ($bannedTypeId) {
				case 1:
					$tableName = 't_log_banned_chat';
					break;

				case 2:
					$tableName = 't_log_banned_role';
					break;
			}


				$sql="
					select
						<selectColumns>
					from
						`{$tableName}` a
					LEFT JOIN
						`t_data_game_area` b
					on
						a.`gameAreaId` = b.`gameAreaId`
					left join
						`t_data_operator` c
					on
						b.`operatorId` = c.`operatorId`
					left JOIN
						`t_data_user_operator_privilege` d
					on
						c.`operatorId` = d.`operatorId`
					AND
						d.`userId` = {$this->currUserId}
					WHERE
						d.`privilegeValue` = 1
					and
						a.`type` = 1
					and
						a.`status` = 1
				";

			$getTotalSql = str_replace('<selectColumns>', "count(*)", $sql);
			$this->returnData['data']['total'] = $this->gmDatabase->getColumn($getTotalSql);

			$getDataSql = str_replace('<selectColumns>', "b.`roleName`, sum(a.`money`) as `money`", $sql);
			$getDataSql .= " order by `money` desc ";

			if($page && $rows) {
				$startRow = ($page - 1) * $rows;
				$getDataSql .= " limit {$startRow}, {$rows}";
			}
			$this->returnData['data']['rows'] = $this->gmDatabase->getArray($getDataSql);
		}
		
		catch(MY_Param_Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		catch(MY_Mysql_Exception $e) {
			$this->setErrorCode(1);
		}
		
		catch(Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		$this->returnJson();
		log_message('debug', '=====调用Role->bannedList->getListData接口结束=====');
	}
}